package com.ximu.user.handler;

import com.alibaba.fastjson.JSON;
import com.ximu.common_utlis.result.Result;
import com.ximu.common_utlis.result.WebUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @projectName: graduation
 * @package: com.ximu.service_ucenter.handler
 * @className: AuthenticationEntryPoint
 * @author: ximu
 * @description: null
 * @date: 2022/5/28 14:16
 * @version: 1.0
 */
//@Component
public class AuthenticationEntryPointImpl {
//    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        Result result = Result.error2().data("error",HttpStatus.UNAUTHORIZED.value()).message("认证失败请重新登录");
        String json = JSON.toJSONString(result);
        WebUtils.renderString(response,json);
    }
}
